<script setup lang="ts">
import { ref, onMounted } from "vue";
import { PAGINATIONFOOT } from "@/utils/staticData";
import router from "@/router";
import { getDictList } from "@/api/dict";

defineOptions({ name: "manageTable" });

defineProps({
  tableHeight: { default: 0, type: Number },
  tableData: { type: Array, default: () => [] },
  pagination: { type: Object, default: () => {} }
});
const tableRef = ref<HTMLTableElement | null>(null);
const relateOrderTypeList = ref([]);
const boundTypeList = ref([]);

/**
 * 跳转详情
 * @param id
 */
const goToDetail = (id: any) => {
  router.push({
    name: "boundSearchPage",
    query: {
      id: id
    }
  });
};

const getRelateOrderTypeList = () => {
  getDictList({ dictCode: "RELATE_ORDER_TYPE" }).then(rsp => {
    relateOrderTypeList.value = rsp.data || [];
  });
};

const getBoundTypeList = () => {
  getDictList({ dictCode: "BOUND_TYPE" }).then(rsp => {
    boundTypeList.value = rsp.data || [];
  });
};

onMounted(() => {
  getRelateOrderTypeList();
  getBoundTypeList();
});

defineExpose({});
</script>

<template>
  <el-table
    ref="tableRef"
    :data="tableData"
    class="tableBox"
    style="width: 100%"
    :height="
      tableHeight - (pagination.total > pagination.size ? PAGINATIONFOOT : 0)
    "
  >
    <el-table-column type="index" label="序号" min-width="88px" />
    <el-table-column
      prop="boundType"
      label="出入库类型"
      min-width="120px"
      show-overflow-tooltip
    >
      <template #default="{ row }">
        <el-text>{{
          boundTypeList.find(val => val.dictLabelValue == row.boundType)
            ?.dictLabelName
        }}</el-text>
      </template>
    </el-table-column>
    <el-table-column
      prop="boundCode"
      label="盘点单编号"
      min-width="184px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="warehouseName"
      label="仓库名称"
      min-width="152px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="relateOrderCode"
      label="关联单号"
      min-width="184px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="relateOrderType"
      label="关联单类型"
      min-width="120px"
      show-overflow-tooltip
    >
      <template #default="{ row }">
        <el-text>{{
          relateOrderTypeList.find(
            val => val.dictLabelValue == row.relateOrderType
          )?.dictLabelName
        }}</el-text>
      </template>
    </el-table-column>
    <el-table-column
      prop="relateStockAbnormalCode"
      label="关联库存异动单号"
      min-width="184px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="createName"
      label="盘点人"
      min-width="104px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="createTime"
      label="单据创建时间"
      min-width="200px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="memo"
      label="备注"
      min-width="200px"
      show-overflow-tooltip
    />
    <el-table-column fixed="right" label="操作" align="left" min-width="80px">
      <template #default="{ row }">
        <el-button type="primary" link @click="goToDetail(row.id)"
          >详情</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
